package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Jaruse;
import com.stylefeng.guns.modular.system.service.IJaruseService;

/**
 * jar包信息控制器
 *
 * @author fengshuonan
 * @Date 2018-10-23 11:00:05
 */
@Controller
@RequestMapping("/jaruse")
public class JaruseController extends BaseController {

    private String PREFIX = "/system/jaruse/";

    @Autowired
    private IJaruseService jaruseService;

    /**
     * 跳转到jar包信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "jaruse.html";
    }

    /**
     * 跳转到添加jar包信息
     */
    @RequestMapping("/jaruse_add")
    public String jaruseAdd() {
        return PREFIX + "jaruse_add.html";
    }

    /**
     * 跳转到修改jar包信息
     */
    @RequestMapping("/jaruse_update/{jaruseId}")
    public String jaruseUpdate(@PathVariable Integer jaruseId, Model model) {
        Jaruse jaruse = jaruseService.selectById(jaruseId);
        model.addAttribute("item",jaruse);
        LogObjectHolder.me().set(jaruse);
        return PREFIX + "jaruse_edit.html";
    }

    /**
     * 获取jar包信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return jaruseService.selectList(null);
    }

    /**
     * 新增jar包信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Jaruse jaruse) {
        jaruseService.insert(jaruse);
        return SUCCESS_TIP;
    }

    /**
     * 删除jar包信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer jaruseId) {
        jaruseService.deleteById(jaruseId);
        return SUCCESS_TIP;
    }

    /**
     * 修改jar包信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Jaruse jaruse) {
        jaruseService.updateById(jaruse);
        return SUCCESS_TIP;
    }

    /**
     * jar包信息详情
     */
    @RequestMapping(value = "/detail/{jaruseId}")
    @ResponseBody
    public Object detail(@PathVariable("jaruseId") Integer jaruseId) {
        return jaruseService.selectById(jaruseId);
    }
}
